import api from '../../http/apis/apis'

export default {
    namespaced: true,
    state: {
        orderList: [],
        currentPage: 1,
        pageSize: 5,
        totalPages: "",
        total: ""
    },
    mutations: {
        //修改订单数组
        setOrderList(state, newList) {
            state.orderList = newList.data;
            state.currentPage = newList.currentPage;
            state.pageSize = newList.pageSize;
            state.totalPages = newList.totalPages;
            state.total = newList.total;
        },
        setPageSize(state, pageSize) {
            console.log('meiye ', pageSize);
            state.pageSize = pageSize;
        },
        //改变当前页
        setCurrent(state, newcurrent) {
            state.currentPage = newcurrent
        },
    },
    actions: {
        //新增订单
        async addOrder(context, params1) {
            const { userID, carID,ownerID, spentMoney, startTime, endTime, spentTime } = params1
            console.log('params1', userID, carID, spentMoney, startTime, endTime, spentTime);
            const { data } = await api.orderApi.addOrder({
                userID, carID, spentMoney, startTime, endTime, spentTime,ownerID
            });
            console.log(data);
        },
        //搜索列表
        async getAllOrder(context, { type, value }) {
            const { data } = await api.orderApi.getOrderList({
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
                value,
                type
            });
            if (data.status) {
                context.commit('setOrderList', data.data)
            }
        },
        //查找订单列表
        async getOrder(context) {
            const { data } = await api.orderApi.getOrder({
                currentPage: context.state.currentPage,
                pageSize: context.state.pageSize,
            });
            if (data.status) {
                context.commit('setOrderList', data.data)
            }
        },
        //通过id查找订单
        async findOrderByID(context, _id) {
            console.log('_id', _id);
            const { data } = await api.orderApi.findOrderByID({ _id });
            return data
        },
        //修改订单状态
        async changeOrderStatus(context,val){
            console.log('仓库',val);
            const {data}=await api.orderApi.changeOrderStatus(val)
            return data
        }


    },
    model: {
    }
}